package com.garen.orm.web;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.garen.common.AbstractAction;
import com.garen.common.AbstractFilter;
import com.garen.common.MsgBean;
import com.garen.orm.ConvertInfo;
import com.garen.orm.biz.IOrmBiz;

/*
 * 完成表导出为类文件
 */
@Controller  
@RequestMapping("/")  
public final class OrmAction extends AbstractAction {

	protected static Log log = LogFactory.getLog(OrmAction.class);   
	
	@Autowired
	private IOrmBiz ormbiz;
	
	@RequestMapping("/ormlist")
	public ModelAndView list(ModelAndView mav) {
		log.debug("精彩马上开始");
		mav.setViewName("sys/ormlist");
		mav.addObject("ormlist", ormbiz.getTables());
		return mav;
	}
	
	//转换保存到磁盘指定路径
	@RequestMapping("/convert")
	public ModelAndView convert(String json) {
		MsgBean mbean = AbstractFilter.getMsgBean(0,"保存成功");
		List<ConvertInfo> infolist = JSON.parseArray(json, ConvertInfo.class);
		ormbiz.convert(infolist);
		return Json(mbean);
	}
	
}
